<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/icon.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/icon.png">
  <link rel="mask-icon" href="/blog/images/icon.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">


<link rel="stylesheet" href="/blog/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"bgape002.gitee.io","root":"/blog/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="关于gitGit 是一个开源的分布式版本控制系统，用于敏捷高效地处理任何或小或大的项目。Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。 安装git包下载各版本下载地址 ps: 如果网速不行，可选择版本号为Git-2.30.1-64-bit">
<meta property="og:type" content="article">
<meta property="og:title" content="Git使用简述">
<meta property="og:url" content="https://bgape002.gitee.io/2021/03/16/Git%E4%BD%BF%E7%94%A8%E7%AE%80%E8%BF%B0/index.html">
<meta property="og:site_name" content="bgape002">
<meta property="og:description" content="关于gitGit 是一个开源的分布式版本控制系统，用于敏捷高效地处理任何或小或大的项目。Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。 安装git包下载各版本下载地址 ps: 如果网速不行，可选择版本号为Git-2.30.1-64-bit">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://www.runoob.com/wp-content/uploads/2015/02/git-process.png">
<meta property="og:image" content="https://www.runoob.com/wp-content/uploads/2015/02/1352126739_7909.jpg">
<meta property="og:image" content="https://bgape002.gitee.io/blog/images/gitee.png">
<meta property="og:image" content="https://bgape002.gitee.io/blog/images/ssh.png">
<meta property="og:image" content="https://bgape002.gitee.io/blog/images/clone-ssh.png">
<meta property="og:image" content="https://bgape002.gitee.io/blog/images/sshF.png">
<meta property="article:published_time" content="2021-03-16T01:08:04.000Z">
<meta property="article:modified_time" content="2022-10-27T06:10:45.215Z">
<meta property="article:author" content="bgape002">
<meta property="article:tag" content="git">
<meta property="article:tag" content="gitee">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://www.runoob.com/wp-content/uploads/2015/02/git-process.png">

<link rel="canonical" href="https://bgape002.gitee.io/2021/03/16/Git%E4%BD%BF%E7%94%A8%E7%AE%80%E8%BF%B0/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Git使用简述 | bgape002</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">bgape002</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">淡泊明志，宁静致远</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">66</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">27</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">61</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://bgape002.gitee.io/2021/03/16/Git%E4%BD%BF%E7%94%A8%E7%AE%80%E8%BF%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/head.png">
      <meta itemprop="name" content="bgape002">
      <meta itemprop="description" content="mail: bgape002@163.com">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="bgape002">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Git使用简述
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-16 09:08:04" itemprop="dateCreated datePublished" datetime="2021-03-16T09:08:04+08:00">2021-03-16</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-10-27 14:10:45" itemprop="dateModified" datetime="2022-10-27T14:10:45+08:00">2022-10-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/git/" itemprop="url" rel="index"><span itemprop="name">git</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/blog/2021/03/16/Git%E4%BD%BF%E7%94%A8%E7%AE%80%E8%BF%B0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/blog/2021/03/16/Git%E4%BD%BF%E7%94%A8%E7%AE%80%E8%BF%B0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="关于git"><a href="#关于git" class="headerlink" title="关于git"></a>关于git</h2><p>Git 是一个<strong>开源的分布式版本控制系统</strong>，用于敏捷高效地处理任何或小或大的项目。Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。</p>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><h3 id="git包下载"><a href="#git包下载" class="headerlink" title="git包下载"></a>git包下载</h3><p><a target="_blank" rel="noopener" href="http://git-scm.com/downloads">各版本下载地址</a></p>
<p>ps: 如果网速不行，可选择版本号为<a target="_blank" rel="noopener" href="https://wws.lanzous.com/iei0bmsn9re">Git-2.30.1-64-bit</a></p>
<span id="more"></span>

<h3 id="git安装"><a href="#git安装" class="headerlink" title="git安装"></a>git安装</h3><p>这里就不赘述了，一直点就完事了。</p>
<h3 id="git配置"><a href="#git配置" class="headerlink" title="git配置"></a>git配置</h3><p>Git 提供了一个叫做 git config 的工具，专门用来配置或读取相应的工作环境变量。</p>
<p><strong>打开git bash</strong></p>
<p>单击鼠标右键&gt;&gt;点击<code>git bash here</code></p>
<p>注意：默认在工作路径为当前位置，可以在目标文件夹进行打开，也可以通过命令切换到目标路径。</p>
<p><font color=red><strong>git bash命令行下可使用Linux系统的常用指令，相当于在windows系统嵌入一个shell bash</strong></font></p>
<p>查看git版本，确认是否安装成功</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git --version</span><br></pre></td></tr></table></figure>

<p>配置个人信息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name <span class="string">&quot;用户名&quot;</span></span><br><span class="line">git config --global user.email <span class="string">&quot;邮件地址&quot;</span></span><br></pre></td></tr></table></figure>

<p>查看配置信息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config -l</span><br></pre></td></tr></table></figure>

<h2 id="git工作流程"><a href="#git工作流程" class="headerlink" title="git工作流程"></a>git工作流程</h2><p><img src="https://www.runoob.com/wp-content/uploads/2015/02/git-process.png" alt="git工作流程图"></p>
<h2 id="git概念：-工作区、暂存区和版本库"><a href="#git概念：-工作区、暂存区和版本库" class="headerlink" title="git概念： 工作区、暂存区和版本库"></a>git概念： 工作区、暂存区和版本库</h2><ul>
<li><strong>工作区：</strong>就是你在电脑里能看到的目录。</li>
<li><strong>暂存区：</strong>英文叫 stage 或 index。一般存放在 <strong>.git</strong> 目录下的 index 文件（.git/index）中，所以我们把暂存区有时也叫作索引（index）。</li>
<li><strong>版本库：</strong>工作区有一个隐藏目录 <strong>.git</strong>，这个不算工作区，而是 Git 的版本库。</li>
</ul>
<p><img src="https://www.runoob.com/wp-content/uploads/2015/02/1352126739_7909.jpg" alt="."></p>
<h2 id="git基本操作"><a href="#git基本操作" class="headerlink" title="git基本操作"></a>git基本操作</h2><h3 id="初始化本地git仓库"><a href="#初始化本地git仓库" class="headerlink" title="初始化本地git仓库"></a>初始化本地git仓库</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git init</span><br></pre></td></tr></table></figure>

<p>该命令是用来初始化git仓库的，是git使用的第一个命令。在执行完成 <code>git init </code>命令后，Git 仓库会<strong>在当前目录</strong>生成一个<code> .git</code> 目录，该目录包含了资源的所有元数据，其他的项目目录保持不变。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git init &lt;newrepo&gt;</span><br></pre></td></tr></table></figure>

<p><code>newrepo</code>为项目仓库文件夹名。初始化后，会在 <code>newrepo </code>目录下会出现一个名为<code>.git</code>的目录，所有 Git 需要的数据和资源都存放在这个目录中。</p>
<h3 id="git-remote-添加远程仓库"><a href="#git-remote-添加远程仓库" class="headerlink" title="git remote 添加远程仓库"></a>git remote 添加远程仓库</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 命令格式</span></span><br><span class="line">git remote add [shortname] [url]</span><br><span class="line">git remote add balbums git@39.105.7.83:/root/repositories/albums</span><br><span class="line"><span class="comment">##############</span></span><br><span class="line">git remote -v     <span class="comment"># 显示所有远程仓库</span></span><br><span class="line">git remote show [remote]   <span class="comment"># 显示某个远程仓库的信息</span></span><br><span class="line">git remote <span class="built_in">rm</span> name   <span class="comment"># 删除远程仓库</span></span><br><span class="line">git remote rename old_name new_name  <span class="comment"># 修改仓库名</span></span><br></pre></td></tr></table></figure>
<h3 id="git-add-添加文件到git暂存区"><a href="#git-add-添加文件到git暂存区" class="headerlink" title="git add 添加文件到git暂存区"></a>git add 添加文件到git暂存区</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git add [file1] [file2] ...           <span class="comment"># 添加一个或多个文件(包括子目录)到暂存区</span></span><br><span class="line">git add .         <span class="comment"># 添加当前目录下的所有文件到暂存区</span></span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git status       <span class="comment"># 命令用于查看在你上次提交之后，是否有对文件进行再次修改</span></span><br></pre></td></tr></table></figure>
<h3 id="git-commit-提交暂存区到本地仓库"><a href="#git-commit-提交暂存区到本地仓库" class="headerlink" title="git commit 提交暂存区到本地仓库"></a>git commit 提交暂存区到本地仓库</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">git commit -m <span class="string">&quot;info&quot;</span>   <span class="comment"># 提交暂存区到本地仓库中；info是一些备注信息</span></span><br><span class="line">git commit [file1] [file2] ... -m <span class="string">&quot;info&quot;</span></span><br><span class="line"></span><br><span class="line">git commit --amend -m <span class="string">&quot;info&quot;</span> 	<span class="comment"># 修改上一次提交的info信息</span></span><br><span class="line">*********************</span><br><span class="line">git commit -a   <span class="comment">#  -a 参数设置修改文件后不需要执行 git add 命令，直接来提交；不推荐使用。</span></span><br></pre></td></tr></table></figure>
<h3 id="git-push-推送本地仓库文件"><a href="#git-push-推送本地仓库文件" class="headerlink" title="git push 推送本地仓库文件"></a>git push 推送本地仓库文件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 从将本地的分支版本上传到远程并合并 命令</span></span><br><span class="line">git push [-f] [--set-upstream] &lt;远程主机名&gt; &lt;本地分支名&gt;:&lt;远程分支名&gt;   </span><br><span class="line">-f 表示强制覆盖（覆盖远端）</span><br><span class="line">--set-upstream 推送到远端的同时建立起和远端分支的关联关系;如果当前分支已经和远端分支关联，则可以省略分支名和远端分支名 // 需远端分支名已存在</span><br><span class="line">-u &lt;=&gt; --set-upstream</span><br><span class="line"><span class="comment">###########</span></span><br><span class="line">git push balbums master:master  <span class="comment"># 分支名相同，;master可省略</span></span><br><span class="line">-----------</span><br><span class="line">git push --set-upstream balbums master</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>

<p><strong>从现有 Git 仓库中拷贝项目</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> &lt;repo&gt; &lt;directory&gt;  			<span class="comment"># 首次从远程仓库拉取代码</span></span><br><span class="line"></span><br><span class="line">git pull [remote name] [brach name]   	<span class="comment"># 下载远程代码并合并</span></span><br></pre></td></tr></table></figure>

<p><code>git clone</code> 从现有 Git 仓库中拷贝项目。<code>directory</code>可以省略，默认当前文件夹。<code>repo</code>为拷贝仓库的地址，如果是链接自己的仓库，这里可以使用ssh密钥来拷贝远程仓库。</p>
<h3 id="git-rm-删除文件操作"><a href="#git-rm-删除文件操作" class="headerlink" title="git rm 删除文件操作"></a>git rm 删除文件操作</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">rm</span> &lt;-f&gt; &lt;file&gt;  <span class="comment"># 暂存区和工作区删除文件file; f&gt;&gt;force</span></span><br><span class="line">git <span class="built_in">rm</span> --cached &lt;file&gt;  <span class="comment"># 保留工作区文件，删除暂存区</span></span><br></pre></td></tr></table></figure>
<h3 id="git-reset-回退版本"><a href="#git-reset-回退版本" class="headerlink" title="git reset 回退版本"></a>git reset 回退版本</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">git reset [--soft | --mixed | --hard] [HEAD]</span><br><span class="line">-----------</span><br><span class="line">git reset --hard HEAD~3  <span class="comment"># 回退上上上一个版本  </span></span><br><span class="line">git reset –hard bae128  <span class="comment"># 回退到某个版本回退点之前的所有信息。 </span></span><br><span class="line">git reset --hard origin/master    <span class="comment"># 将本地的状态回退到和远程的一样 </span></span><br><span class="line">-----------</span><br><span class="line"><span class="comment"># --mixed 为默认，可以不用带该参数，用于重置暂存区的文件与上一次的提交(commit)保持一致，工作区文件内容保持不变</span></span><br><span class="line">git reset HEAD^            <span class="comment"># 回退所有内容到上一个版本  </span></span><br><span class="line">git reset HEAD^ hello.php  <span class="comment"># 回退 hello.php 文件的版本到上一个版本  </span></span><br><span class="line">git  reset  052e           <span class="comment"># 回退到指定版本</span></span><br><span class="line">--------------</span><br><span class="line"><span class="comment"># --soft 参数用于回退到某个版本, 只进行对commit操作的回退，不影响工作区的文件</span></span><br><span class="line">git reset --soft HEAD~3   <span class="comment"># 回退上上上一个版本 </span></span><br><span class="line">--------------</span><br><span class="line"><span class="comment"># --hard 参数撤销工作区中所有未提交的修改内容，将暂存区与工作区都回到上一次版本，并删除之前的所有信息提交</span></span><br><span class="line"><span class="comment"># 会对当前工作文件进行回退</span></span><br><span class="line">$ git reset --hard HEAD~3  <span class="comment"># 回退上上上一个版本  </span></span><br><span class="line">$ git reset --hard bae128  <span class="comment"># 回退到某个版本回退点之前的所有信息。 </span></span><br><span class="line">$ git reset --hard origin/master    <span class="comment"># 将本地的状态回退到和远程的一样 </span></span><br><span class="line">---------------</span><br><span class="line">可以使用 ～数字表示</span><br><span class="line">HEAD~0 表示当前版本</span><br><span class="line">HEAD~1 上一个版本</span><br><span class="line">HEAD^2 上上一个版本</span><br><span class="line">HEAD^3 上上上一个版本</span><br></pre></td></tr></table></figure>



<h3 id="git-tag-添加版本标签"><a href="#git-tag-添加版本标签" class="headerlink" title="git tag 添加版本标签"></a>git tag 添加版本标签</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 如果你达到一个重要的阶段，并希望永远记住那个特别的提交快照，你可以使用 `git tag` 给它打上标签。</span></span><br><span class="line"><span class="comment"># 比如说，我们想为我们的项目发布一个&quot;1.0&quot;版本，可以用 `git tag -a v1.0 `命令给最新一次提交打上（HEAD）&quot;v1.0&quot;的标签。</span></span><br><span class="line">git tag -a v1.0    <span class="comment"># -a 选项意为&quot;创建一个带注解的标签&quot;</span></span><br><span class="line">git tag -a &lt;tagname&gt; -m <span class="string">&quot;info&quot;</span>    <span class="comment"># 指定标签信息命令</span></span><br></pre></td></tr></table></figure>



<h3 id="git-其他操作"><a href="#git-其他操作" class="headerlink" title="git 其他操作"></a>git 其他操作</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">mv</span> [file] [newfile]   <span class="comment"># 移动或重命名工作区文件</span></span><br><span class="line">-----------</span><br><span class="line">git diff [file]    <span class="comment"># 比较文件的不同，即暂存区和工作区的差异</span></span><br><span class="line"><span class="comment"># 尚未缓存的改动：git diff</span></span><br><span class="line"><span class="comment"># 查看已缓存的改动： git diff --cached</span></span><br><span class="line"><span class="comment"># 查看已缓存的与未缓存的所有改动：git diff HEAD</span></span><br><span class="line"><span class="comment"># 显示摘要而非整个 diff：git diff --stat</span></span><br><span class="line"></span><br><span class="line">git diff &lt;file&gt; <span class="comment"># 比较当前文件和暂存区文件差异 git diff</span></span><br><span class="line">git diff &lt;id1&gt;&lt;id1&gt;&lt;id2&gt; <span class="comment"># 比较两次提交之间的差异</span></span><br><span class="line">git diff &lt;branch1&gt; &lt;branch2&gt; <span class="comment"># 在两个分支之间比较</span></span><br><span class="line">git diff --staged <span class="comment"># 比较暂存区和版本库差异</span></span><br><span class="line">git diff --cached <span class="comment"># 比较暂存区和版本库差异</span></span><br><span class="line">git diff --<span class="built_in">stat</span> <span class="comment"># 仅仅比较统计信息</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">------------</span><br><span class="line">git fetch [remote name] [brach name]   <span class="comment"># 从远程获取代码库，抓取更新但不合并</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>




<h2 id="git-分支管理"><a href="#git-分支管理" class="headerlink" title="git 分支管理"></a>git 分支管理</h2><h3 id="开发中分支使用原则与流程"><a href="#开发中分支使用原则与流程" class="headerlink" title="开发中分支使用原则与流程"></a>开发中分支使用原则与流程</h3><p>在开发中，一般有如下分支使用原则与流程：</p>
<ul>
<li><p>master（生产）分支</p>
<p>线上分支，主分支，中小规模项目作为线上运行的应用对应分支；</p>
</li>
<li><p>develop（开发）分支</p>
<p>从master创建的分支，一般作为开发部门的主要开发分支，如果没有其他并行开发不同期上线要求，都可以在此版本进行开发，阶段开发完成后，需要合并到master分支，准备上线；</p>
</li>
<li><p>feature分支</p>
<p>从develop创建的分支，一般是同期并行开发，但不同期上线时创建的分支，分支上的研发任务完成后合并到develop分支；</p>
</li>
<li><p>hotfix分支</p>
<p>从master派生的分支，一般作为线上bug修复使用，修复完成后需要合并到master，develop，test分支；</p>
</li>
<li><p>其他分支，如test分支（用于代码测试），pre分支（预上线分支）</p>
</li>
</ul>
<h3 id="分支操作命令"><a href="#分支操作命令" class="headerlink" title="分支操作命令"></a>分支操作命令</h3><h3 id="创建分支命令："><a href="#创建分支命令：" class="headerlink" title="创建分支命令："></a>创建分支命令：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">git branch &lt;branchName&gt;</span><br><span class="line"><span class="comment"># git branch 创建新分支，需要在master分支正式建立后，才能进行，也即第一次git commit操作后</span></span><br><span class="line">----------------------</span><br><span class="line">git branch dev  <span class="comment"># 创建dev分支</span></span><br><span class="line">git branch -d dev  <span class="comment"># 删除dev分支</span></span><br><span class="line">git branch -D dev  <span class="comment"># 强制删除dev分支，一般在未进行merge操作的前提下删除分支，会需要-D确认删除</span></span><br><span class="line">---------------------</span><br><span class="line">git branch -vv  <span class="comment"># 查看本地分支与远端分支的绑定关系</span></span><br><span class="line">-------------------</span><br><span class="line">git branch &lt;branchName&gt; &lt;oldBranchName&gt; 	<span class="comment"># 在oldBranchName分支上新建分支branchName</span></span><br></pre></td></tr></table></figure>
<h3 id="git-checkout-切换分支命令"><a href="#git-checkout-切换分支命令" class="headerlink" title="git checkout 切换分支命令:"></a>git checkout 切换分支命令:</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git checkout (branchname)</span><br><span class="line">-------------------</span><br><span class="line">git checkout -b dev  <span class="comment"># 创建并切换到dev分支</span></span><br><span class="line">git checkout -b dev master <span class="comment"># 在master分支上创建并切换到dev分支</span></span><br></pre></td></tr></table></figure>
<p>当你切换分支的时候，Git 会用该分支的最后提交的快照替换你的工作目录的内容， 所以多个分支不需要多个目录。</p>
<h3 id="git-merge-合并分支命令"><a href="#git-merge-合并分支命令" class="headerlink" title="git merge 合并分支命令:"></a>git merge 合并分支命令:</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">git merge </span><br><span class="line"><span class="comment"># 一般合并操作的合并到master分支上</span></span><br><span class="line"><span class="comment"># 合并操作的流程为：切换到master分支，合并</span></span><br><span class="line">git checkout master</span><br><span class="line">git merge dev   <span class="comment"># 将分支dev合并到当前分支中，自动进行新的提交</span></span><br><span class="line">git merge --no-commit maint  <span class="comment"># 将分支maint合并到当前分支中，但不要自动进行新的提交</span></span><br></pre></td></tr></table></figure>

<h3 id="列出分支基本命令"><a href="#列出分支基本命令" class="headerlink" title="列出分支基本命令"></a>列出分支基本命令</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch  <span class="comment"># (没有参数时，`git branch` 会列出你在本地的分支)：</span></span><br></pre></td></tr></table></figure>
<h3 id="删除分支命令："><a href="#删除分支命令：" class="headerlink" title="删除分支命令："></a>删除分支命令：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git branch -d (branchname)  <span class="comment"># 删除本地分支</span></span><br><span class="line">git branch -D (branchname)  <span class="comment"># 强制删除本地分支</span></span><br><span class="line">git push origin --delete (branchname)  <span class="comment"># 删除远程分支</span></span><br></pre></td></tr></table></figure>

<h2 id="git-日志"><a href="#git-日志" class="headerlink" title="git 日志"></a>git 日志</h2><p>使用<code>git log</code> 查看历史操作日志</p>
<p>查看日志命令：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">git blame &lt;file&gt;    <span class="comment"># 以列表形式查看指定文件的历史修改记录</span></span><br><span class="line">git <span class="built_in">log</span></span><br><span class="line"><span class="comment"># 以单行图形化形式查看详细日志信息</span></span><br><span class="line">git <span class="built_in">log</span> --oneline --all --graph --abbrev-commit</span><br><span class="line">git <span class="built_in">log</span> --color --graph --pretty=format:<span class="string">&#x27;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset&#x27;</span> --abbrev-commit</span><br></pre></td></tr></table></figure>


<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 如果不带任何参数，它会列出所有历史记录，最近的排在最上方，显示提交对象的哈希值，作者、提交日期、和提交说明</span></span><br><span class="line"><span class="comment"># 如果记录过多，则按Page Up、Page Down、↓、↑来控制显示</span></span><br><span class="line">--------------</span><br><span class="line"><span class="comment"># 按q退出历史记录列表</span></span><br></pre></td></tr></table></figure>

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><span class="line">-<span class="selector-tag">p</span>：按补丁显示每个更新间的差异，比下一条- -stat命令信息更全</span><br><span class="line"><span class="attr">--stat</span>：显示每次更新的修改文件的统计信息，每个提交都列出了修改过的文件，以及其中添加和移除的行数，并在最后列出所有增减行数小计</span><br><span class="line"><span class="attr">--shortstat</span>：只显示<span class="attr">--stat</span>中最后的行数添加修改删除统计</span><br><span class="line"><span class="attr">--name-only</span>：尽在已修改的提交信息后显示文件清单</span><br><span class="line"><span class="attr">--name-status</span>：显示新增、修改和删除的文件清单</span><br><span class="line"><span class="attr">--abbrev-commit</span>：仅显示SHA-<span class="number">1</span>的前几个字符，而非所有的<span class="number">40</span>个字符</span><br><span class="line"><span class="attr">--relative-date</span>：使用较短的相对时间显示（例如：&quot;two weeks ago&quot;）</span><br><span class="line"><span class="attr">--graph</span>：显示ASCII图形表示的分支合并历史</span><br><span class="line">—pretty＝：使用其他格式显示历史提交信息，可选项有：oneline,short,medium,full,fuller,email,raw以及format:&lt;string&gt;,默认为medium，如：</span><br><span class="line">    --pretty=oneline：一行显示，只显示哈希值和提交说明（--online本身也可以作为单独的属性）</span><br><span class="line">    --pretty=format:” <span class="string">&quot;：控制显示的记录格式，如：</span></span><br><span class="line"><span class="string">        %H  提交对象（commit）的完整哈希字串</span></span><br><span class="line"><span class="string">        %h  提交对象的简短哈希字串</span></span><br><span class="line"><span class="string">        %T  树对象（tree）的完整哈希字串</span></span><br><span class="line"><span class="string">        %t  树对象的简短哈希字串</span></span><br><span class="line"><span class="string">        %P  父对象（parent）的完整哈希字串</span></span><br><span class="line"><span class="string">        %p  父对象的简短哈希字串</span></span><br><span class="line"><span class="string">        %an 作者（author）的名字</span></span><br><span class="line"><span class="string">        %ae 作者的电子邮件地址</span></span><br><span class="line"><span class="string">        %ad 作者修订日期（可以用 -date= 选项定制格式）</span></span><br><span class="line"><span class="string">        %ar 作者修订日期，按多久以前的方式显示</span></span><br><span class="line"><span class="string">        %cn 提交者(committer)的名字</span></span><br><span class="line"><span class="string">            作者和提交者的区别不知道是啥？</span></span><br><span class="line"><span class="string">            作者与提交者的关系：作者是程序的修改者，提交者是代码提交人</span></span><br><span class="line"><span class="string">			（自己的修改不提交是怎么能让别人拉下来再提交的？）</span></span><br><span class="line"><span class="string">            其实作者指的是实际作出修改的人，提交者指的是最后将此工作成果提交到仓库的人。</span></span><br><span class="line"><span class="string">			当你为某个项目发布补丁，某个核心成员将你的补丁并入项目，你就是作者，而那个核心成员就是提交者</span></span><br><span class="line"><span class="string">        %ce 提交者的电子邮件地址</span></span><br><span class="line"><span class="string">        %cd 提交日期（可以用 -date= 选项定制格式）</span></span><br><span class="line"><span class="string">        %cr 提交日期，按多久以前的方式显示</span></span><br><span class="line"><span class="string">        %s  提交说明</span></span><br><span class="line"><span class="string">    带颜色的--pretty=format:” &quot;</span>，这个另外写出来分析</span><br><span class="line">        以这句为例：%Cred%h%Creset -%<span class="built_in">C</span>(yellow)%d%Cblue %s %<span class="built_in">Cgreen</span>(%cd) %<span class="built_in">C</span>(bold blue)&lt;%an&gt; </span><br><span class="line">        先断句：［%Cred%h］［%Creset   -］［%<span class="built_in">C</span>(yellow)%d ］［%Cblue%s］［%<span class="built_in">Cgreen</span>(%cd)］［%<span class="built_in">C</span>(bold blue)&lt;%an&gt;］</span><br><span class="line">        然后就是很明显能得到的规律了</span><br><span class="line">            一个颜色＋一个内容</span><br><span class="line">            颜色以％C开头，后边接几种颜色，还可以设置字体，如果要设置字体的话，要一块加个括号</span><br><span class="line">                能设置的颜色值包括：reset（默认的灰色），normal, black, red, green, yellow, blue, magenta, cyan, white.</span><br><span class="line">                字体属性则有bold, dim, ul, blink, reverse.  </span><br><span class="line">            内容可以是占位元字符，也可以是直接显示的普通字符</span><br><span class="line">--------------------------------------------------------</span><br><span class="line">-------------------------------------------------</span><br><span class="line">--date= (relative|local|default|iso|rfc|short|raw)：定制后边如果出现%ad或%cd时的日期格式</span><br><span class="line">    有几个默认选项</span><br><span class="line">        --date=relative：shows dates relative to the current time, e.g. <span class="string">&quot;2 hours ago&quot;</span>.</span><br><span class="line">        --date=local：shows timestamps in user’s local timezone.</span><br><span class="line">        --date=iso (or --date=iso8601)：shows timestamps in ISO <span class="number">8601</span> format.</span><br><span class="line">        --date=rfc (or --date=rfc2822)：shows timestamps in RFC <span class="number">2822</span> format,often found in E-mail messages.</span><br><span class="line">        --date=short：shows only date but not time, in YYYY-MM-DD format.这个挺好用</span><br><span class="line">        --date=raw：shows the date in the internal raw git format %s %z format.</span><br><span class="line">        --date=default：shows timestamps in the original timezone (either committer’s or author’s).</span><br><span class="line">    也可以自定义格式（需要git版本<span class="number">2.6</span>.<span class="number">0</span>以上），比如--date=format:<span class="string">&#x27;%Y-%m-%d %H:%M:%S&#x27;</span> 会格式化成：<span class="number">2016</span>-<span class="number">01</span>-<span class="number">13</span> <span class="number">11</span>:<span class="number">32</span>:<span class="number">13</span>，其他的格式化占位符如下：</span><br><span class="line">        %a：Abbreviated weekday name</span><br><span class="line">        %A：Full weekday name</span><br><span class="line">        %b：Abbreviated month name</span><br><span class="line">        %B：Full month name</span><br><span class="line">        %c：Date and time representation appropriate for locale</span><br><span class="line">        %d：Day of month as decimal number (<span class="number">01</span> – <span class="number">31</span>)</span><br><span class="line">        %H： Hour in <span class="number">24</span>-hour format (<span class="number">00</span> – <span class="number">23</span>)</span><br><span class="line">        %I：Hour in <span class="number">12</span>-hour format (<span class="number">01</span> – <span class="number">12</span>)</span><br><span class="line">        %j：Day of year as decimal number (<span class="number">001</span> – <span class="number">366</span>)</span><br><span class="line">        %m：Month as decimal number (<span class="number">01</span> – <span class="number">12</span>)</span><br><span class="line">        %M：Minute as decimal number (<span class="number">00</span> – <span class="number">59</span>)</span><br><span class="line">        %p：Current locale<span class="string">&#x27;s A.M./P.M. indicator for 12-hour clock</span></span><br><span class="line"><span class="string">        %S：Second as decimal number (00 – 59)</span></span><br><span class="line"><span class="string">        %U：Week of year as decimal number, with Sunday as first day of week (00 – 53)</span></span><br><span class="line"><span class="string">        %w：Weekday as decimal number (0 – 6; Sunday is 0)</span></span><br><span class="line"><span class="string">        %W：Week of year as decimal number, with Monday as first day of week (00 – 53)</span></span><br><span class="line"><span class="string">        %x：Date representation for current locale</span></span><br><span class="line"><span class="string">        %X：Time representation for current locale</span></span><br><span class="line"><span class="string">        %y：Year without century, as decimal number (00 – 99)</span></span><br><span class="line"><span class="string">        %Y：Year with century, as decimal number</span></span><br><span class="line"><span class="string">        %z, %Z：Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown</span></span><br><span class="line"><span class="string">        %%：Percent sign</span></span><br><span class="line"><span class="string"></span></span><br></pre></td></tr></table></figure>

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line">按数量</span><br><span class="line">    -n：显示前n条log</span><br><span class="line">按日期</span><br><span class="line">    <span class="attr">--after</span>=</span><br><span class="line">        比如git log <span class="attr">--after</span>=&quot;<span class="number">2014</span>-<span class="number">7</span>-<span class="number">1</span>”，显示<span class="number">2014</span>年<span class="number">7</span>月<span class="number">1</span>号之后的commit(包含<span class="number">7</span>月<span class="number">1</span>号)</span><br><span class="line">        后边的日期还可以用相对时间表示，比如&quot;<span class="number">1</span> week ago&quot;和”yesterday&quot;，比如git log <span class="attr">--after</span>=&quot;yesterday&quot;</span><br><span class="line">        这里的格式可以是什么？</span><br><span class="line">    <span class="attr">--before</span>=</span><br><span class="line">        同上</span><br><span class="line">        另外这两条命令可以同时使用表示时间段，比如git log <span class="attr">--after</span>=&quot;<span class="number">2014</span>-<span class="number">7</span>-<span class="number">1</span>&quot; <span class="attr">--before</span>=&quot;<span class="number">2014</span>-<span class="number">7</span>-<span class="number">4</span>&quot;</span><br><span class="line">        另外<span class="attr">--since</span> <span class="attr">--until</span>和 <span class="attr">--after</span> <span class="attr">--before</span>是一个意思，都可以用</span><br><span class="line">按作者</span><br><span class="line">    <span class="attr">--author</span>=</span><br><span class="line">        比如git log <span class="attr">--author</span>=“John&quot;，显示John贡献的commit</span><br><span class="line">        注意：作者名不需要精确匹配，只需要包含就行了</span><br><span class="line">        而且：可以使用正则表达式，比如git log <span class="attr">--author</span>=&quot;John|Mary”，搜索Marry和John贡献的commit</span><br><span class="line">        而且：这个<span class="attr">--author</span>不仅包含名还包含email, 所以你可以用这个搜索email</span><br><span class="line">按commit描述</span><br><span class="line">    <span class="attr">--grep</span>=</span><br><span class="line">        比如：git log <span class="attr">--grep</span>=&quot;JRA-<span class="number">224</span>&quot;</span><br><span class="line">        而且：可以传入-<span class="selector-tag">i</span>用来忽略大小写</span><br><span class="line">        注意：如果想同时使用<span class="attr">--grep</span>和<span class="attr">--author</span>，必须在附加一个<span class="attr">--all-match</span>参数</span><br><span class="line">按文件</span><br><span class="line">    - -（空格）或［没有］</span><br><span class="line">        有时你可能只对某个文件的修改感兴趣, 你只想查看跟某个文件相关的历史信息, 你只需要插入你感兴趣文件的路径［对，是路径，所以经常是不太好用］就可以了</span><br><span class="line">        比如：git log -- foo<span class="selector-class">.py</span> bar<span class="selector-class">.py</span> ，只返回和foo<span class="selector-class">.py</span>或bar<span class="selector-class">.py</span>相关的commit</span><br><span class="line">        这里的--是告诉Git后面的参数是文件路径而不是branch的名字. 如果后面的文件路径不会和某个branch产生混淆, 你可以省略- -，比如git log foo<span class="selector-class">.py</span> </span><br><span class="line">        另外，后边的路径还支持正则，比如：git log  *install<span class="selector-class">.md</span> 是，指定项目路径下的所有以install<span class="selector-class">.md</span>结尾的文件的提交历史</span><br><span class="line">        另外，文件名应该放到参数的最后位置，通常在前面加上--并用空格隔开表示是文件</span><br><span class="line">        另外，git log file/ 查看file文件夹下所有文件的提交记录</span><br><span class="line">按分支</span><br><span class="line">    - -</span><br><span class="line">        <span class="attr">--branchName</span> branchName为任意一个分支名字，查看某个分支上的提交记录</span><br><span class="line">        需要放到参数中的最后位置处</span><br><span class="line">        如果分支名与文件名相同，系统会提示错 误，可通过--选项来指定给定的参数是分支名还是文件名</span><br><span class="line">            比如：在当前分支中有一个名为v1的文件，同时还存在一个名为v1的分支</span><br><span class="line">            git log v1 -- 此时的v1代表的是分支名字（－－后边是空的）</span><br><span class="line">            git log -- v1 此时的v1代表的是名为v1的文件</span><br><span class="line">            git log v1 －－ v1 代表v1分支下的v1文件</span><br><span class="line">按内容</span><br><span class="line">    -S&quot;&lt;string&gt;&quot;、-G&quot;&lt;string&gt;&quot;</span><br><span class="line">        有时你想搜索和新增或删除某行代码相关的commit. 可以使用这条命令</span><br><span class="line">        假设你想知道Hello, World!这句话是什么时候加入到项目里去的，可以用：git log -S&quot;Hello,World!&quot;</span><br><span class="line">        另外：如果你想使用正则表达式去匹配而不是字符串, 那么你可以使用-G代替-S.</span><br><span class="line">        这是一个非常有用的debug工具, 使用他你可以定位所有跟某行代码相关的commit. 甚至可以查看某行是什么时候被copy的, 什么时候移到另外一个文件中去的</span><br><span class="line">        注：-S后没有&quot;=&quot;，与查询内容之间也没有空格符</span><br><span class="line">按范围</span><br><span class="line">    git log &lt;since&gt;..&lt;until&gt;</span><br><span class="line">        这个命令可以查看某个范围的commit</span><br><span class="line">        这个命令非常有用当你使用branch做为range参数的时候. 能很方便的显示<span class="number">2</span>个branch之间的不同</span><br><span class="line">        比如：git log master.<span class="selector-class">.feature</span>，master.<span class="selector-class">.feature</span>这个range包含了在feature有而在master没有的所有commit，同样，如果是feature.<span class="selector-class">.master</span>包含所有master有但是feature没有的commit</span><br><span class="line">        另外，如果是三个点，表示或的意思：git log master..<span class="selector-class">.test</span> 查询master或test分支中的提交记录</span><br><span class="line">过滤掉merge commit</span><br><span class="line">    <span class="attr">--no-merges</span></span><br><span class="line">        默认情况下git log会输出merge commit.  你可以通过<span class="attr">--no-merges</span>标记来过滤掉merge commit，git log <span class="attr">--no-merges</span></span><br><span class="line">        另外，如果你只对merge commit感兴趣可以使用—merges，git log <span class="attr">--merges</span></span><br><span class="line">按标签tag</span><br><span class="line">    git log v1.<span class="number">0</span></span><br><span class="line">        直接这样是查询标签之前的commit</span><br><span class="line">        加两个点git log v1.<span class="number">0</span>.. 查询从v1.<span class="number">0</span>以后的提交历史记录(不包含v1.<span class="number">0</span>)</span><br><span class="line">按commit</span><br><span class="line">    git log commit ：查询commit之前的记录，包含commit</span><br><span class="line">    git log commit1 commit2：查询commit1与commit2之间的记录，包括commit1和commit2</span><br><span class="line">    git log commit1.<span class="selector-class">.commit2</span>：同上，但是不包括commit1</span><br><span class="line">        其中，commit可以是提交哈希值的简写模式，也可以使用HEAD代替</span><br><span class="line">            HEAD代表最后一次提交，HEAD^为最后一个提交的父提交，等同于HEAD～<span class="number">1</span></span><br><span class="line">            HEAD～<span class="number">2</span>代表倒数第二次提交</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="git-reflog-查看HEAD和分支引用在过去指向的位置记录"><a href="#git-reflog-查看HEAD和分支引用在过去指向的位置记录" class="headerlink" title="git reflog 查看HEAD和分支引用在过去指向的位置记录"></a>git reflog 查看HEAD和分支引用在过去指向的位置记录</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reflog show [branchname]</span><br></pre></td></tr></table></figure>

<h3 id="git-shortlog-日志汇总"><a href="#git-shortlog-日志汇总" class="headerlink" title="git shortlog 日志汇总"></a>git shortlog 日志汇总</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -s 参数省略每次 commit 的注释，仅仅返回一个简单的统计。</span></span><br><span class="line"><span class="comment"># -n 参数按照 commit 数量从多到少的顺利对用户进行排序</span></span><br><span class="line">git shortlog -s -n</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="git-submodule"><a href="#git-submodule" class="headerlink" title="git submodule"></a>git submodule</h2><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_43976461/article/details/125926991">git submodule详解</a></p>
<h2 id="其他操作"><a href="#其他操作" class="headerlink" title="其他操作"></a>其他操作</h2><h3 id="git-config-配置git操作信息"><a href="#git-config-配置git操作信息" class="headerlink" title="git config 配置git操作信息"></a>git config 配置git操作信息</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 配置git命令（以别名的形式，配置现有的git操作集）</span></span><br><span class="line"><span class="comment"># --add 添加配置项</span></span><br><span class="line">git config [--<span class="built_in">local</span>|--global|--system] --add section.key value</span><br><span class="line"><span class="comment"># --local 默认项，本地配置，配置文件位置 .git/config</span></span><br><span class="line"><span class="comment"># --global 当前用户全局配置，配置文件位置 ~/.gitconfig</span></span><br><span class="line"><span class="comment"># --system 所有用户全局配置，配置文件位置 /etc/gitconfig</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># --add 可省略，默认</span></span><br><span class="line">git config --global alias.lg <span class="string">&quot;log --color --graph --pretty=format:&#x27;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset&#x27; --abbrev-commit&quot;</span></span><br><span class="line">git lg  <span class="comment"># 替代后面一长串</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 全局配置文件修改情况：</span></span><br><span class="line"><span class="comment"># [alias]</span></span><br><span class="line"><span class="comment">#         lg = log --color --graph --pretty=format:&#x27;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset&#x27; --abbrev-commit</span></span><br><span class="line"></span><br><span class="line">---</span><br><span class="line">git config alias.llg <span class="string">&quot;log --oneline --all --graph --abbrev-commit&quot;</span></span><br><span class="line">-----------------------------</span><br><span class="line"><span class="comment"># --unset 删除配置信息</span></span><br><span class="line">git config [--<span class="built_in">local</span>|--global|--system] --<span class="built_in">unset</span> section.key</span><br><span class="line"></span><br><span class="line">git config --global -–<span class="built_in">unset</span> alias.lg</span><br><span class="line"><span class="comment"># 全局配置文件中该结点信息会被删除</span></span><br><span class="line"></span><br><span class="line">-------------------------------------</span><br><span class="line">-------------------------------------</span><br><span class="line">-------------------------------------</span><br><span class="line"><span class="comment"># alias别名设置方式：</span></span><br><span class="line"><span class="comment"># 1. 通过git config配置 (推荐)</span></span><br><span class="line"><span class="comment"># 2. 直接按照格式修改配置文件</span></span><br><span class="line"><span class="comment"># 3. 修改 .bashrc文件</span></span><br></pre></td></tr></table></figure>



<h2 id="gitee-码云"><a href="#gitee-码云" class="headerlink" title="gitee(码云)"></a>gitee(码云)</h2><p>如果你知道<code>github</code>的话，把<code>gitee</code>看成国内版本就好了。<a target="_blank" rel="noopener" href="https://gitee.com/">gitee地址</a></p>
<blockquote>
<p>Gitee 提供免费的 Git 仓库，还集成了代码质量检测、项目演示等功能。对于团队协作开发，Gitee 还提供了项目管理、代码托管、文档管理的服务，5 人以下小团队免费。</p>
</blockquote>
<h3 id="gitee-新建仓库"><a href="#gitee-新建仓库" class="headerlink" title="gitee 新建仓库"></a>gitee 新建仓库</h3><p>登陆网站&gt;&gt;注册账号&gt;&gt;点击右上头像边的<code>+</code>&gt;&gt;新建仓库</p>
<p>然后，该点的点，该填的填。</p>
<p>这里最后<code>创建</code>上面有个<code>导入已有仓库</code>，可以通过这个位置，把<code>github</code>上的仓库给导入进来。<code>github</code>访问慢的同学，可以通过这样的方式去下载 。</p>
<p><img src="/blog/images/gitee.png" alt="gitee建仓"></p>
<p><strong>SSH与gitee</strong></p>
<p>查看系统中是否存在<code>.ssh</code>文件夹（Everything搜吧，一般在C盘的用户目录下，如果不存在：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -C <span class="string">&quot;xxxxx@xxxxx.com&quot;</span></span><br></pre></td></tr></table></figure>

<p>连续回车键，生成文件。打开<code>.ssh</code>文件夹下的<code>id_rsa.pub</code>，全选复制</p>
<p>打开gitee的设置界面&gt;&gt;SSH公钥&gt;&gt;粘贴进<strong>公钥</strong>对应的框&gt;&gt;确定</p>
<p><img src="/blog/images/ssh.png" alt="gitee-ssh"></p>
<p><strong>远程仓库与本地仓库连接</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> &lt;SSH&gt;</span><br></pre></td></tr></table></figure>

<p><code>&lt;SSH&gt;</code>为项目地址，可从gitee对应仓库中复制获取。</p>
<p><img src="/blog/images/clone-ssh.png" alt="ssh地址"></p>
<p><strong>第一次使用该命令可能会出现</strong>：</p>
<p><img src="/blog/images/sshF.png" alt="ssh-error"></p>
<p>输入<code>yes</code>后回车</p>
<p>PS：如果是之前存在<code>.ssh</code>文件夹报错，建议删了按步骤来一遍。</p>
<h2 id="个人git服务器搭建"><a href="#个人git服务器搭建" class="headerlink" title="个人git服务器搭建"></a>个人git服务器搭建</h2><h3 id="–bare-“裸仓库”"><a href="#–bare-“裸仓库”" class="headerlink" title="–bare “裸仓库”"></a>–bare “裸仓库”</h3><p><strong><code>git init 与 git init --bare</code>差异对比</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">git init albums</span><br><span class="line">tree -aL 2 albums</span><br><span class="line"><span class="comment">#####################</span></span><br><span class="line">albums</span><br><span class="line">└── .git</span><br><span class="line">    ├── branches</span><br><span class="line">    ├── config</span><br><span class="line">    ├── description</span><br><span class="line">    ├── HEAD</span><br><span class="line">    ├── hooks</span><br><span class="line">    ├── info</span><br><span class="line">    ├── objects</span><br><span class="line">    └── refs</span><br><span class="line"><span class="comment">######################</span></span><br><span class="line">git init --bare albums.git</span><br><span class="line">tree -aL 2 albums.git</span><br><span class="line"><span class="comment">#####################</span></span><br><span class="line">albums.git</span><br><span class="line">├── branches</span><br><span class="line">├── config</span><br><span class="line">├── description</span><br><span class="line">├── HEAD</span><br><span class="line">├── hooks</span><br><span class="line">│   ├── applypatch-msg.sample</span><br><span class="line">│   ├── commit-msg.sample</span><br><span class="line">│   ├── post-update.sample</span><br><span class="line">│   ├── pre-applypatch.sample</span><br><span class="line">│   ├── pre-commit.sample</span><br><span class="line">│   ├── prepare-commit-msg.sample</span><br><span class="line">│   ├── pre-push.sample</span><br><span class="line">│   ├── pre-rebase.sample</span><br><span class="line">│   └── update.sample</span><br><span class="line">├── info</span><br><span class="line">│   └── exclude</span><br><span class="line">├── objects</span><br><span class="line">│   ├── info</span><br><span class="line">│   └── pack</span><br><span class="line">└── refs</span><br><span class="line">    ├── heads</span><br><span class="line">    └── tags</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>功能差异</strong></p>
<ul>
<li><code> --bare</code>参数创建的仓库（<code>albums.git</code>）一般叫“裸仓库”，里面没有工作区的概念，不能直接在仓库里进行正常的git命令操作； 该仓库可以推送的项目文件，但无法对文件进行任何操作。</li>
<li><code>albums</code>仓库 可以直接在上面进行git操作 ，推送（<code>git push</code>）会报错</li>
<li>一般，默认git仓库目录命为<code>directoryName.git</code>；在系统中创建用户名为<code>git</code>的用户，并关闭该用户的<code>bash</code>权限，作为服务器仓库连接用户。</li>
</ul>
<h2 id="搭建git服务器"><a href="#搭建git服务器" class="headerlink" title="搭建git服务器"></a>搭建git服务器</h2><p>设你已经有<code>sudo</code>权限的用户账号，下面，正式开始安装。</p>
<p><strong>无法在root用户下创建git仓库</strong></p>
<p>第一步，安装<code>git</code>：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ sudo apt-get install git</span><br></pre></td></tr></table></figure>

<p>第二步，创建一个<code>git</code>用户，用来运行<code>git</code>服务：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ sudo adduser git</span><br></pre></td></tr></table></figure>

<p>第三步，创建证书登录：</p>
<p>收集所有需要登录的用户的公钥，就是他们自己的<code>id_rsa.pub</code>文件，把所有公钥导入到<code>/home/git/.ssh/authorized_keys</code>文件里，一行一个。</p>
<p>第四步，初始化Git仓库：</p>
<p>先选定一个目录作为Git仓库，假定是<code>/srv/sample.git</code>，在<code>/srv</code>目录下输入命令：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ sudo git init --bare sample.git</span><br></pre></td></tr></table></figure>

<p>Git就会创建一个裸仓库，裸仓库没有工作区，因为服务器上的Git仓库纯粹是为了共享，所以不让用户直接登录到服务器上去改工作区，并且服务器上的Git仓库通常都以<code>.git</code>结尾。然后，把owner改为<code>git</code>：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ sudo chown -R git:git sample.git</span><br></pre></td></tr></table></figure>

<p>第五步，禁用shell登录：</p>
<p>出于安全考虑，第二步创建的git用户不允许登录shell，这可以通过编辑<code>/etc/passwd</code>文件完成。找到类似下面的一行：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git:x:1001:1001:,,,:/home/git:/bin/bash</span><br></pre></td></tr></table></figure>

<p>改为：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell</span><br></pre></td></tr></table></figure>

<p>这样，<code>git</code>用户可以正常通过ssh使用git，但无法登录shell，因为我们为<code>git</code>用户指定的<code>git-shell</code>每次一登录就自动退出。</p>
<p>第六步，克隆远程仓库：</p>
<p>现在，可以通过<code>git clone</code>命令克隆远程仓库了，在各自的电脑上运行：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ git clone git@server:/srv/sample.git</span><br><span class="line">Cloning into &#x27;sample&#x27;...</span><br><span class="line">warning: You appear to have cloned an empty repository.</span><br></pre></td></tr></table></figure>

<p>剩下的推送就简单了。</p>
<h2 id="参考文献"><a href="#参考文献" class="headerlink" title="参考文献"></a>参考文献</h2><font size=2>

<p>[1] <a target="_blank" rel="noopener" href="https://www.runoob.com/git/git-tutorial.html">Git 教程</a></p>
<p>[2] <a target="_blank" rel="noopener" href="https://www.cnblogs.com/fightjianxian/p/11916828.html">The authenticity of host can’t be established.</a></p>
<p>[3] <a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1MU4y1Y7h5">黑马程序员Git全套教程</a></p>
<p>[4] <a target="_blank" rel="noopener" href="https://www.liaoxuefeng.com/wiki/896043488029600/899998870925664">搭建Git服务器</a></p>
<p>[5] <a target="_blank" rel="noopener" href="https://www.yiibai.com/git">Git教程</a></p>
<p>[6] <a target="_blank" rel="noopener" href="https://blog.csdn.net/u012260238/article/details/81673853">git log命令全解析</a></p>
</font>


    </div>

    
    
    

      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/blog/tags/git/" rel="tag"><i class="fa fa-tag"></i> git</a>
              <a href="/blog/tags/gitee/" rel="tag"><i class="fa fa-tag"></i> gitee</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2021/03/13/hexo-next-%E4%B8%BB%E9%A2%98%E9%85%8D%E7%BD%AE/" rel="prev" title="hexo next 主题配置">
      <i class="fa fa-chevron-left"></i> hexo next 主题配置
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2021/03/17/hexo-gitee-%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/" rel="next" title="hexo-gitee 搭建个人博客">
      hexo-gitee 搭建个人博客 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>


        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%B3%E4%BA%8Egit"><span class="nav-number">1.</span> <span class="nav-text">关于git</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E8%A3%85"><span class="nav-number">2.</span> <span class="nav-text">安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#git%E5%8C%85%E4%B8%8B%E8%BD%BD"><span class="nav-number">2.1.</span> <span class="nav-text">git包下载</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git%E5%AE%89%E8%A3%85"><span class="nav-number">2.2.</span> <span class="nav-text">git安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git%E9%85%8D%E7%BD%AE"><span class="nav-number">2.3.</span> <span class="nav-text">git配置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#git%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B"><span class="nav-number">3.</span> <span class="nav-text">git工作流程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#git%E6%A6%82%E5%BF%B5%EF%BC%9A-%E5%B7%A5%E4%BD%9C%E5%8C%BA%E3%80%81%E6%9A%82%E5%AD%98%E5%8C%BA%E5%92%8C%E7%89%88%E6%9C%AC%E5%BA%93"><span class="nav-number">4.</span> <span class="nav-text">git概念： 工作区、暂存区和版本库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#git%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="nav-number">5.</span> <span class="nav-text">git基本操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96%E6%9C%AC%E5%9C%B0git%E4%BB%93%E5%BA%93"><span class="nav-number">5.1.</span> <span class="nav-text">初始化本地git仓库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-remote-%E6%B7%BB%E5%8A%A0%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93"><span class="nav-number">5.2.</span> <span class="nav-text">git remote 添加远程仓库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-add-%E6%B7%BB%E5%8A%A0%E6%96%87%E4%BB%B6%E5%88%B0git%E6%9A%82%E5%AD%98%E5%8C%BA"><span class="nav-number">5.3.</span> <span class="nav-text">git add 添加文件到git暂存区</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-commit-%E6%8F%90%E4%BA%A4%E6%9A%82%E5%AD%98%E5%8C%BA%E5%88%B0%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93"><span class="nav-number">5.4.</span> <span class="nav-text">git commit 提交暂存区到本地仓库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-push-%E6%8E%A8%E9%80%81%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93%E6%96%87%E4%BB%B6"><span class="nav-number">5.5.</span> <span class="nav-text">git push 推送本地仓库文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-rm-%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C"><span class="nav-number">5.6.</span> <span class="nav-text">git rm 删除文件操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-reset-%E5%9B%9E%E9%80%80%E7%89%88%E6%9C%AC"><span class="nav-number">5.7.</span> <span class="nav-text">git reset 回退版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-tag-%E6%B7%BB%E5%8A%A0%E7%89%88%E6%9C%AC%E6%A0%87%E7%AD%BE"><span class="nav-number">5.8.</span> <span class="nav-text">git tag 添加版本标签</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-%E5%85%B6%E4%BB%96%E6%93%8D%E4%BD%9C"><span class="nav-number">5.9.</span> <span class="nav-text">git 其他操作</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#git-%E5%88%86%E6%94%AF%E7%AE%A1%E7%90%86"><span class="nav-number">6.</span> <span class="nav-text">git 分支管理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%BC%80%E5%8F%91%E4%B8%AD%E5%88%86%E6%94%AF%E4%BD%BF%E7%94%A8%E5%8E%9F%E5%88%99%E4%B8%8E%E6%B5%81%E7%A8%8B"><span class="nav-number">6.1.</span> <span class="nav-text">开发中分支使用原则与流程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%86%E6%94%AF%E6%93%8D%E4%BD%9C%E5%91%BD%E4%BB%A4"><span class="nav-number">6.2.</span> <span class="nav-text">分支操作命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="nav-number">6.3.</span> <span class="nav-text">创建分支命令：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-checkout-%E5%88%87%E6%8D%A2%E5%88%86%E6%94%AF%E5%91%BD%E4%BB%A4"><span class="nav-number">6.4.</span> <span class="nav-text">git checkout 切换分支命令:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-merge-%E5%90%88%E5%B9%B6%E5%88%86%E6%94%AF%E5%91%BD%E4%BB%A4"><span class="nav-number">6.5.</span> <span class="nav-text">git merge 合并分支命令:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%97%E5%87%BA%E5%88%86%E6%94%AF%E5%9F%BA%E6%9C%AC%E5%91%BD%E4%BB%A4"><span class="nav-number">6.6.</span> <span class="nav-text">列出分支基本命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E5%88%86%E6%94%AF%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="nav-number">6.7.</span> <span class="nav-text">删除分支命令：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#git-%E6%97%A5%E5%BF%97"><span class="nav-number">7.</span> <span class="nav-text">git 日志</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#git-reflog-%E6%9F%A5%E7%9C%8BHEAD%E5%92%8C%E5%88%86%E6%94%AF%E5%BC%95%E7%94%A8%E5%9C%A8%E8%BF%87%E5%8E%BB%E6%8C%87%E5%90%91%E7%9A%84%E4%BD%8D%E7%BD%AE%E8%AE%B0%E5%BD%95"><span class="nav-number">7.1.</span> <span class="nav-text">git reflog 查看HEAD和分支引用在过去指向的位置记录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-shortlog-%E6%97%A5%E5%BF%97%E6%B1%87%E6%80%BB"><span class="nav-number">7.2.</span> <span class="nav-text">git shortlog 日志汇总</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#git-submodule"><span class="nav-number">8.</span> <span class="nav-text">git submodule</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%B6%E4%BB%96%E6%93%8D%E4%BD%9C"><span class="nav-number">9.</span> <span class="nav-text">其他操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#git-config-%E9%85%8D%E7%BD%AEgit%E6%93%8D%E4%BD%9C%E4%BF%A1%E6%81%AF"><span class="nav-number">9.1.</span> <span class="nav-text">git config 配置git操作信息</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#gitee-%E7%A0%81%E4%BA%91"><span class="nav-number">10.</span> <span class="nav-text">gitee(码云)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#gitee-%E6%96%B0%E5%BB%BA%E4%BB%93%E5%BA%93"><span class="nav-number">10.1.</span> <span class="nav-text">gitee 新建仓库</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%AA%E4%BA%BAgit%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%90%AD%E5%BB%BA"><span class="nav-number">11.</span> <span class="nav-text">个人git服务器搭建</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E2%80%93bare-%E2%80%9C%E8%A3%B8%E4%BB%93%E5%BA%93%E2%80%9D"><span class="nav-number">11.1.</span> <span class="nav-text">–bare “裸仓库”</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%90%AD%E5%BB%BAgit%E6%9C%8D%E5%8A%A1%E5%99%A8"><span class="nav-number">12.</span> <span class="nav-text">搭建git服务器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="nav-number">13.</span> <span class="nav-text">参考文献</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="bgape002"
      src="/blog/images/head.png">
  <p class="site-author-name" itemprop="name">bgape002</p>
  <div class="site-description" itemprop="description">mail: bgape002@163.com</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">61</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">27</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">66</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2021 – 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">bgape002</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  




  
<script src="/blog/js/local-search.js"></script>











<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : 'forest',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


  

  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'szhBf0Qamzsowubi1WnkXmUj-gzGzoHsz',
      appKey     : 'WpwxoK0fVJHvhzWwakr9vbpA',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
